<?php
$page_name=basename($_SERVER['SCRIPT_FILENAME']);
$IsPreserved	= 'Y';
$IsProcess		= $_REQUEST['IsProcess'];
include("general_include.php");
include "checklogin.php";
if($IsProcess <> 'Y')
{
	include "top.php";
	//include "left.php";
}	

$item_per_page=$_SESSION['item_per_page'] = $_REQUEST['item_per_page'];
	if(empty($item_per_page) || !isset($item_per_page))
	{
	$item_per_page=10;
	} 

$action	= $_REQUEST['action'];


if($action=="del")
{	
	if(!empty($delete_id))
	{
	  $DelSql = "DELETE FROM ".TABLEPREFIX."_video where video_id='$delete_id'";
	  $UserManagerObjAjax->Execute($DelSql);
	}  
}  
function findvalue($table,$fld_name,$fld_value,$find_value)
{
     if($fld_value=='')
			return false;
			
		$SelectTypeSql = "SELECT ".$find_value." FROM ".$table." WHERE $fld_name=".$fld_value;
		$SelectType = mysql_fetch_array(mysql_query($SelectTypeSql));
		return $SelectType[0];
}	


$CoachvdoSql = "SELECT * FROM ".TABLEPREFIX."_video where user_id='".$_SESSION['user_id']."' ORDER BY date_added DESC";
$PaginationObjAjaxLatest=new PaginationClassAjax($item_per_page,"prev",'',"next","active",$adodbcon);
$pagination_arr = $PaginationObjAjaxLatest->PaginationAjax($CoachvdoSql,$page_name."?action=".$action."&item_per_page=".$item_per_page,"Managergeneral");	
$CoachvdoArr = $UserManagerObjAjax->GetRecords("All",$CoachvdoSql);
$Numcoachvdo=count($CoachvdoArr);

for($v=0;$v<$Numcoachvdo;$v++)
{
    $CoachvdoArr[$v]['game']= findvalue(TABLEPREFIX."_game","game_id",$CoachvdoArr[$v]['game_id'],"game_name");
	$CoachvdoArr[$v]['ladder']= findvalue(TABLEPREFIX."_game_ladder","ladder_id",$CoachvdoArr[$v]['ladder_id'],"ladder_name");
	$CoachvdoArr[$v]['race']= findvalue(TABLEPREFIX."_game_race","race_id",$CoachvdoArr[$v]['race_id'],"race_title");
	$CoachvdoArr[$v]['description']= stripslashes($CoachvdoArr[$v]['description']);
	
	$SelectteamSql="SELECT * FROM ".TABLEPREFIX."_game_team WHERE  game_id=".$CoachvdoArr[$v]['game_id']." AND team_id IN (".$CoachvdoArr[$v]["team_id"].")";
	$RsteamSql = $UserManagerObjAjax->GetRecords("All",$SelectteamSql);	
	

	for($i=0;$i<count($RsteamSql);$i++)
	{	
			if($i<(count($RsteamSql)-1)) 	
				$coma=",";
			else
				$coma="";
			$CoachvdoArr[$v]['team'] = $CoachvdoArr[$v]['team'].$RsteamSql[$i]['team_title'].$coma;
	}
	
	$SelectmapSql="SELECT * FROM ".TABLEPREFIX."_game_map WHERE game_id=".$CoachvdoArr[$v]['game_id']." AND map_id IN (".$CoachvdoArr[$v]["map_id"].")";
	$RsmapSql = $UserManagerObjAjax->GetRecords("All",$SelectmapSql);	
	
	$CoachvdoArr[$v]['map']='';
	for($i=0;$i<count($RsmapSql);$i++)
	{		
			if($i<(count($RsmapSql)-1)) 	
				$coma=",";
			else
				$coma="";
			$CoachvdoArr[$v]['map'] = $CoachvdoArr[$v]['map'].$RsmapSql[$i]['map_title'].$coma;
	}
	
	$SelectclassSql="SELECT * FROM ".TABLEPREFIX."_game_class WHERE game_id=". $CoachvdoArr[$v]['game_id']." AND class_id IN (".$CoachvdoArr[$v]["class_id"].")";
	$RsclassSql = $UserManagerObjAjax->GetRecords("All",$SelectclassSql);	
	
    $CoachvdoArr[$v]['class']='';
	for($i=0;$i<count($RsclassSql);$i++)
	{		
			if($i<(count($RsclassSql)-1)) 	
				$coma=",";
			else
				$coma="";
			$CoachvdoArr[$v]['class'] = $CoachvdoArr[$v]['class'].$RsclassSql[$i]['class_title'].$coma;
	}
	$SelectversusSql="SELECT * FROM ".TABLEPREFIX."_game_versus WHERE game_id=". $CoachvdoArr[$v]['game_id']." AND versus_id IN (".$CoachvdoArr[$v]["versus_id"].")";
	$RsversusSql = $UserManagerObjAjax->GetRecords("All",$SelectversusSql);	
	
    $CoachvdoArr[$v]['versus']='';
	for($i=0;$i<count($RsversusSql);$i++)
	{		
			if($i<(count($RsversusSql)-1)) 	
				$coma=",";
			else
				$coma="";
			$CoachvdoArr[$v]['versus'] = $CoachvdoArr[$v]['versus'].$RsversusSql[$i]['versus_title'].$coma;
	}
	$SelecttypeSql="SELECT * FROM ".TABLEPREFIX."_game_type WHERE game_id=". $CoachvdoArr[$v]['game_id']." AND type_id IN (".$CoachvdoArr[$v]["type_id"].")";
	$RstypeSql = $UserManagerObjAjax->GetRecords("All",$SelecttypeSql);	
	
    $CoachvdoArr[$v]['type']='';
	for($i=0;$i<count($RstypeSql);$i++)
	{		
			if($i<(count($RstypeSql)-1)) 	
				$coma=",";
			else
				$coma="";
			$CoachvdoArr[$v]['type'] = $CoachvdoArr[$v]['type'].$RstypeSql[$i]['type_title'].$coma;
	}
	$SelectchampSql="SELECT * FROM ".TABLEPREFIX."_game_champion WHERE game_id=". $CoachvdoArr[$v]['game_id']." AND champion_id IN (".$CoachvdoArr[$v]["champion_id"].")";
	$RschampSql = $UserManagerObjAjax->GetRecords("All",$SelectchampSql);	
	
    $CoachvdoArr[$v]['champion']='';
	for($i=0;$i<count($RschampSql);$i++)
	{		
			if($i<(count($RschampSql)-1)) 	
				$coma=",";
			else
				$coma="";
			$CoachvdoArr[$v]['champ'] = $CoachvdoArr[$v]['champion'].$RschampSql[$i]['champion_title'].$coma;
	}
	$SelectmodeSql="SELECT * FROM ".TABLEPREFIX."_game_mode WHERE game_id=". $CoachvdoArr[$v]['game_id']." AND mode_id IN (".$CoachvdoArr[$v]["mode_id"].")";
	$RsmodeSql = $UserManagerObjAjax->GetRecords("All",$SelectmodeSql);	
	
    $CoachvdoArr[$v]['mode']='';
	for($i=0;$i<count($RsmodeSql);$i++)
	{		
			if($i<(count($RsmodeSql)-1)) 	
				$coma=",";
			else
				$coma="";
			$CoachvdoArr[$v]['mode'] = $CoachvdoArr[$v]['mode'].$RsmodeSql[$i]['mode_title'].$coma;
	}
	
	$LikeSql = "SELECT count(*) AS numlike FROM ".TABLEPREFIX."_user_like WHERE video_id=".$CoachvdoArr[$v]['video_id']." AND selected_for='L'" ;
	$LikeArr = $UserManagerObjAjax->GetRecords('Row',$LikeSql);
		
	$CoachvdoArr[$v]['numlike']=$LikeArr['numlike'];
	
	$UnlikeSql = "SELECT count(*) AS numunlike FROM ".TABLEPREFIX."_user_like WHERE video_id=".$CoachvdoArr[$v]['video_id']." AND selected_for='D'" ;
	$UnlikeArr = $UserManagerObjAjax->GetRecords('Row',$UnlikeSql);
		
	$CoachvdoArr[$v]['numunlike']=$UnlikeArr['numunlike'];
	
}

if($IsProcess == 'Y')
{
   $Sqltype = "SELECT * FROM ".TABLEPREFIX."_user_type_user_relation WHERE user_id='".$_SESSION['user_id']."'";
	$typeArr = $UserManagerObjAjax->GetRecords("All",$Sqltype);
	$Numtype = count($typeArr);
	$is_coach = 0;
	$is_partner = 0;
	for($t=0;$t<$Numtype;$t++)
	{
	   if($typeArr[$t]['user_type_id']==1)
		  $is_coach = 1;
	   if($typeArr[$t]['user_type_id']==3)
		  $is_partner = 1;
	}
}
$smarty->assign('is_coach',$is_coach);
$smarty->assign('is_partner',$is_partner);
$smarty->assign('pagination_arr',$pagination_arr);
$smarty->assign('Numcoachvdo',$Numcoachvdo);
$smarty->assign('CoachvdoArr',$CoachvdoArr);
$smarty->assign('page_name',$page_name);
$smarty->display('upload_videos.tpl');
if($IsProcess<>'Y')
  include "footer.php";
?>